//
//  TagCollectionViewCell.m
//  WHTestDome
//
//  Created by Assistant on 9/22/25.
//

#import "TagCollectionViewCell.h"

@interface TagCollectionViewCell ()

@property (nonatomic, strong) UILabel *titleLabelInternal;

@end

@implementation TagCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
        self.contentView.layer.cornerRadius = 10.0;
        self.contentView.layer.masksToBounds = YES;
        self.layer.shadowColor = [UIColor clearColor].CGColor;

        _titleLabelInternal = [[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabelInternal.translatesAutoresizingMaskIntoConstraints = NO;
        _titleLabelInternal.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
        _titleLabelInternal.textAlignment = NSTextAlignmentCenter;
        _titleLabelInternal.textColor = [UIColor labelColor];
        [self.contentView addSubview:_titleLabelInternal];

        [NSLayoutConstraint activateConstraints:@[
            [_titleLabelInternal.centerXAnchor constraintEqualToAnchor:self.contentView.centerXAnchor],
            [_titleLabelInternal.centerYAnchor constraintEqualToAnchor:self.contentView.centerYAnchor]
        ]];
    }
    return self;
}

- (UILabel *)titleLabel {
    return self.titleLabelInternal;
}

- (void)setTagSelected:(BOOL)tagSelected {
    _tagSelected = tagSelected;
    if (tagSelected) {
        self.contentView.backgroundColor =[UIColor colorWithRed:(54)/255.0 green:(141)/255.0 blue:(246)/255.0 alpha:0.3];
        self.contentView.layer.borderColor = [UIColor colorWithRed:(54)/255.0 green:(141)/255.0 blue:(246)/255.0 alpha:1.0].CGColor;
        self.contentView.layer.borderWidth = 1.0;
        self.titleLabelInternal.textColor = [UIColor colorWithRed:(54)/255.0 green:(141)/255.0 blue:(246)/255.0 alpha:1.0];
        self.titleLabelInternal.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
    } else {
        self.contentView.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
        self.contentView.layer.borderWidth = 0.0;
        self.titleLabelInternal.textColor = [UIColor labelColor];
        self.titleLabelInternal.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
    }
}

- (void)prepareForReuse {
    [super prepareForReuse];
    self.tagSelected = NO;
    self.titleLabelInternal.text = @"";
}

- (void)configureWithTitle:(NSString *)title selected:(BOOL)selected {
    self.titleLabelInternal.text = title;
    self.tagSelected = selected;
}

@end


